<template>
    <div>
        <div class="background">
            <section class="header">
                <video autoplay loop class="void-background" muted plays-inlne>
                    <source src="../mv/G1s.mp4" type="video/mp4"/>
                    浏览器不支持 video 标签，建议升级浏览器。
                </video>
            </section>
        </div>
        <div style="margin: 0 auto;">
            <el-card style="width: 400px;margin: 0 auto;text-align: center; background: rgba(255,255,255,0.8);">
                <div slot="header" class="clearfix">
                    <span>修改</span>
                    <h2>{{ this.filters.id = this.$route.query.index }}</h2>
                </div>
                <el-form :model="updateUser" ref="registerForm" inline>
                    <el-form-item label="名字">
                        <el-input v-model="updateUser.name"></el-input>
                    </el-form-item>
                    <br>
                    <el-form-item label="诗词">
                        <el-input v-model="updateUser.poetry"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="update">修改</el-button>
                        <el-button @click="$router.push('/admin')">返回</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </div>
    </div>
</template>

<script>
    export default {
        name: "update",
        data() {
            return {
                updateUser: {},
                filters: {
                    id: '',
                }
            }
        },

        methods: {
            update() {
                // 用PATCH方式调用后端接口
                this.$axios.patch(`/api/character/${this.filters.id}`, this.updateUser).then((res) => {
                    if (res.data.status === 1) {
                        // 如果创建成功
                        this.updateUser = {};
                        this.$message.success('修改成功');
                    } else {
                        this.$message.error('修改失败');
                    }
                })
            }

        },

    }
</script>

<style scoped>

</style>